<include file="public/layout" />
<style>
.ncm-goods-gift {
	text-align: left;
}
.ncm-goods-gift ul {
    display: inline-block;
    font-size: 0;
    vertical-align: middle;
}
.ncm-goods-gift li {
    display: inline-block;
    letter-spacing: normal;
    margin-right: 4px;
    vertical-align: top;
    word-spacing: normal;
}
.ncm-goods-gift li a {
    background-color: #fff;
    display: table-cell;
    height: 30px;
    line-height: 0;
    overflow: hidden;
    text-align: center;
    vertical-align: middle;
    width: 30px;
}
.ncm-goods-gift li a img {
    max-height: 30px;
    max-width: 30px;
}

a.green{
	
	background: #fff none repeat scroll 0 0;
    border: 1px solid #f5f5f5;
    border-radius: 4px;
    color: #999;
    cursor: pointer !important;
    display: inline-block;
    font-size: 12px;
    font-weight: normal;
    height: 20px;
    letter-spacing: normal;
    line-height: 20px;
    margin: 0 5px 0 0;
    padding: 1px 6px;
    vertical-align: top;
}

a.green:hover { color: #FFF; background-color: #1BBC9D; border-color: #16A086; }

.ncap-order-style .ncap-order-details{
	margin:20px auto;
}
.contact-info h3,.contact-info .form_class{
  display: inline-block;
  vertical-align: middle;
}
.form_class i.fa{
  vertical-align: text-bottom;
}
</style>
<div class="page">
  <div class="fixed-bar">
    <div class="item-title"><a class="back" href="javascript:history.go(-1)" title="返回列表"><i class="fa fa-arrow-circle-o-left"></i></a>
      <div class="subject">
        <h3>商品订单</h3>
        <h5>商城实物商品交易订单查询及管理</h5>
      </div>
      <div class="subject" style="width:62%">
	     <if condition="$order['order_status'] lt 2 and $order.pay_status eq 0">
      		<a href="{:U('Admin/order/edit_order',array('order_id'=>$order['order_id']))}" style="float:right;margin-right:10px" class="ncap-btn-big ncap-btn-green" ><i class="fa fa-pencil-square-o"></i>修改订单</a>
      	 </if>
      	 <if condition="$order['is_split']">
      		<a href="{:U('Admin/order/split_order',array('order_id'=>$order['order_id']))}" style="float:right;margin-right:10px" class="ncap-btn-big ncap-btn-green" ><i class="fa fa-external-link-square"></i>拆分订单</a>
      	 </if>
      	 <a href="{:U('Order/order_print',array('order_id'=>$order['order_id']))}" target="_blank"  style="float:right;margin-right:10px" class="ncap-btn-big ncap-btn-green" ><i class="fa fa-print"></i>打印订单</a>
      </div>
    </div>
      
  </div>
  <div class="ncap-order-style">
    <div class="titile">
      <h3></h3>
    </div>
 
    <div class="ncap-order-details">
      <form id="order-action">
          <input name="order_id" value="{$order['order_id']}" type="hidden"/>
        <div class="tabs-panels">
            <div class="misc-info">
                <h3>基本信息</h3>
                <dl>
                    <dt>订单 ID：</dt>
                    <dd>{$order.order_id}</dd>
                    <dt>订单号：</dt>
                    <dd>{$order.order_sn}</dd>
                    <dt>会员：</dt>
                    <dd>{$order.users.nickname}  ID:{$order.user_id}</dd>
                </dl>
                <dl>
                    <dt>E-Mail：</dt>
                    <dd>{$order.email}</dd>
                    <dt>电话：</dt>
                    <dd>{$order.mobile}</dd>
                    <dt>应付金额：</dt>
                    <dd>{$order.order_amount}</dd>
                </dl>
                <dl>
                    <dt>订单状态：</dt>
                    <dd>{$order_status[$order[order_status]]} / {$pay_status[$order[pay_status]]}
                        <if condition="$order['pay_code'] eq 'cod'"><span style="color: red">(货到付款)</span></if>
                        / {$shipping_status[$order[shipping_status]]}
                    </dd>
                    <dt>下单时间：</dt>
                    <dd>{$order.add_time|date='Y-m-d H:i',###}</dd>
                    <dt>支付时间：</dt>
                    <dd>
                        <if condition="$order.pay_time neq 0">{$order.pay_time|date='Y-m-d H:i',###}
                            <else/>
                            N
                        </if>
                    </dd>
                </dl>
                <dl>
                    <dt>支付方式：</dt>
                    <dd>{$order.pay_name|default='其他方式'}</dd>
                    <dt>发票抬头：</dt>
                    <dd>{$order.invoice_title|default='N'}</dd>
                    <dt>纳税人识别号：</dt>
                    <dd>{$order.taxpayer|default='N'}</dd>
                </dl>
            </div>
            <div class="addr-note">
                <h4>收货信息</h4>
                <dl>
                    <dt>{$order.consignee_desc}：</dt>
                    <dd>{$order.consignee}</dd>
                    <dt>联系方式：</dt>
                    <dd>{$order.mobile}</dd>
                </dl>
                <dl>
                    <if condition="$order['shop_id'] gt 0">
                    <dt>自提点：</dt>
                    <dd>{$order.shop.shop_name}</dd>
                    </if>
                    <dt>收货地址：</dt>
                    <dd>{$order.full_address}</dd>
                </dl>
                <dl>
                    <dt>邮编：</dt>
                    <dd>{$order.zipcode|default='N'}</dd>
                    <if condition="$order['shop_id'] gt 0">
                        <dt>自提时间：</dt>
                        <dd>{$order.shop_order.take_time}</dd>
                    </if>
                </dl>
                <dl>
                    <dt>配送方式：</dt>
                    <dd>{$order.delivery_method}</dd>
                    <if condition="$order['shop_id'] gt 0">
                        <dt>快递公司：</dt>
                        <foreach name="$order['delivery_doc']" item="v">
                            <dd>{$v.shipping_name} -- {$v.invoice_no}</dd>
                        </foreach>
                    </if>
                </dl>
                <dl>
                    <dt>留言：</dt>
                    <dd>{$order.user_note|default=''}</dd>
                </dl>
            </div>
  
         
        <div class="goods-info">
          <h4>商品信息</h4>
          <table>
            <thead>
              <tr>
                <th >商品编号</th>
                <th colspan="2">商品</th>
                <th>规格属性</th>
                <th>数量</th>
                <th>商品价格</th>
                <th>会员折扣价</th>
                <th>商品小计</th>
              </tr>
            </thead>
            <tbody>
            <volist name="$order.orderGoods" id="good">
           	<tr>
                <td class="w60">{$good.goods_sn}</td>
                <td class="w30"><div class="goods-thumb"><a href="{:U('Home/Goods/goodsInfo',array('id'=>$good['goods_id']))}" target="_blank"><img alt="" src="{$good['goods_id']|goods_thum_images=200,200}" /> </a></div></td>
                <td style="text-align: left;"><a href="{:U('Home/Goods/goodsInfo',array('id'=>$good['goods_id']))}" target="_blank">{$good.goods_name}</a><br/></td>
                <td class="w80">{$good.spec_key_name}</td>
                <td class="w60">{$good.goods_num}</td>
                <td class="w100">{$good.goods_price}</td>
                <td class="w60">{$good.member_goods_price}</td>
                <td class="w80">{$good.total_member_goods_price}</td>
              </tr>
              </volist>
          </table>
        </div>
        <div class="total-amount contact-info">
          <h3>订单总额：￥{$order.goods_price}</h3>
        </div>
         <if condition="$order['shipping_status'] eq 1">
            <foreach name="$order['delivery_doc']" item="v">
                <div class="goods-info">
                    <h4>物流信息</h4>
                    <table id="express_info">
                        <thead>
                        <tr>
                            <th>操作时间</th>
                            <th>状态</th>
                        </tr>
                        </thead>
                        <tbody>

                    </table>
                </div>
                <script>
                    $(function(){
                        var shipping_code = "{$v['shipping_code']}";
                        var invoice_no = "{$v['invoice_no']}";
                        $.ajax({
                            type : "GET",
                            dataType: "json",
                            url:"/index.php?m=Home&c=Api&a=queryExpress&shipping_code="+shipping_code+"&invoice_no="+invoice_no,//+tab,
                            success: function(data){
                                var html = '';
                                if(data.status == 200){
                                    $.each(data.data, function(i,n){
                                        if(i == 0){
                                            html += '<tr><td class="text-center">'+n.time+'</td><td class="text-center">'+n.context+'</td></tr>'
                                        }else{
                                            html += '<tr><td class="text-center">'+n.time+'</td><td class="text-center">'+n.context+'</td></tr>'
                                        }
                                    });
                                }else{
                                    html += "<tr><td class='text-center'>"+data.message+"</td></tr>"
                                }
                                $("#express_info").append(html);
                            }
                        });
                    })
                </script>
            </foreach>
        </if>
        <div class="contact-info">
          <h3>费用信息 </h3>
            <if condition="$order.pay_status eq 0">
              <div class="form_class">
                    <a class="btn green" href="{:U('Admin/Order/editprice',array('order_id'=>$order['order_id']))}"><i class="fa fa-pencil-square-o"></i>修改费用</a>
              </div>
            </if>
          <dl>
            <dt>小计：</dt>
            <dd>{$order.goods_price}</dd>
            <dt>运费：</dt>
            <dd>+{$order.shipping_price}</dd>
            <dt>积分 (-{$order.integral})：</dt>
            <dd>-{$order.integral_money}</dd>
          </dl>
          <dl>
            <dt>余额抵扣：</dt>
            <dd>-{$order.user_money}</dd>
            <dt>优惠券抵扣：</dt>
            <dd>-{$order.coupon_price}</dd>
            <dt>价格调整：</dt>
            <dd>减：{$order.discount}</dd>
          </dl>
          <dl>
            <dt>应付：</dt>
            <dd><strong class="red_common">{$order.order_amount}</strong></dd>
           </dl>
        </div>
        <div class="contact-info">
          <h3>操作信息</h3>
          <dl class="row">
	        <dt class="tit">
	          <label for="note">操作备注</label>
	        </dt>
	        <dd class="opt" style="margin-left:10px">
	         <textarea id="note" name="note" style="width:600px" rows="6"  maxlength="200" placeholder="请输入操作备注" class="tarea">{$keyword.text}</textarea>
	        </dd>
	      </dl> 
	      <dl class="row">
	        <dt class="tit">
	          <label for="note">可执行操作</label>
	        </dt>
	        <dd class="opt" style="margin-left:10px">
	         	<foreach name="$order.adminOrderButton" item="vo" key="k">
               		<if condition="$k eq 'pay_cancel'">
               			<!--<a class="ncap-btn-big ncap-btn-green" href="javascript:void(0)" data-url="{:U('Order/pay_cancel',array('order_id'=>$order['order_id']))}" onclick="pay_cancel(this)">{$vo}</a>-->
                        <a class="ncap-btn-big ncap-btn-green" onclick="verifyForm('order-action','{:U('Admin/order/order_action',array('type'=>$k))}');" >{$vo}</a>
               		<elseif condition="$k eq 'delivery'"/>
                        <if condition="$order.shop_id eq 0">
               			    <a class="ncap-btn-big ncap-btn-green" href="{:U('Order/delivery_info',array('order_id'=>$order['order_id']))}">{$vo}</a>
                            <else/>
                            <a class="ncap-btn-big ncap-btn-green" onclick="deliverGoods({$order.order_id})">{$vo}</a>
                        </if>
               		<elseif condition="$k eq 'refund'"/>
               		<else/>
               		<a class="ncap-btn-big ncap-btn-green" onclick="verifyForm('order-action','{:U('Admin/order/order_action',array('type'=>$k))}');" >
               		{$vo}</a>
               		</if>
               	</foreach>
	        </dd>
	      </dl> 
        </div>
        <div class="goods-info">
          <h4>操作记录</h4>
          <table>
            <thead>
              <tr>
                <th>操作者</th>
                <th>操作时间</th>
                <th>订单状态</th>
                <th>付款状态</th>
                <th>发货状态</th>
                <th>描述</th>
                <th>备注</th>
              </tr>
            </thead>
              <tbody id="order_action">
              </tbody>
          </table>
        </div>
      </div>
      </form>
  	</div>
  </div>
</div>
<div class="z-ztfh-bg" hidden>
</div>
<div class="z-ztfh-pop" hidden>
    <form>
        <div class="z-ztfh-head">
            <i class="z-ztfh-close"></i>
            <h3>商品发货</h3>
        </div>
        <div class="z-ztfh-tab">
            <ul class="tab-ul-title">
                <li style="width: 21%;">订单编号</li>
                <li style="width: 24%;">下单时间</li>
                <li style="width: 15%;">会员ID</li>
                <li style="width: 15%;">订单总额</li>
                <li style="width: 12%;">发货状态</li>
                <li style="width: 12%;">配送方式</li>
            </ul>
            <ul class="tab-ul-cont" id="shop-order-info">
            </ul>
        </div>
        <div class="z-ztfh-information">
            <h5>自提信息:</h5>
            <div class="ztfh-information-cont" id="shop-info"></div>
        </div>
        <div class="z-ztfh-select">
            <span>提供方式:</span>
            <div class="z-ztfh-hema ztfh-label">
                <label ints="1" class="ztfh-lab-bg" data-val="1"></label>核码提货
            </div>
            <div class="z-ztfh-wuma ztfh-label">
                <label data-val="0"></label>无码提货
            </div>
        </div>
        <div class="z-ztfh-input">
            <span>提      货 &nbsp;码:</span>
            <label  ></label>
            <input type="hidden" name="old_shop_order_id" id="old-shop-order-id" />
            <input type="text" name="shop_order_id" id="shop-order-id" placeholder="请输入提货码" />
        </div>
        <div class="z-ztfh-btns">
            <label></label>
            <input type="button" id="fahuo" value="发货" />
        </div>
    </form>
</div>
<script type="text/javascript">
    $(function () {
        getOrderAction();
    })
    function delfun() {
        // 删除按钮
        layer.confirm('确认删除？', {
            btn: ['确定'] //按钮
        }, function () {
            console.log("确定");
        }, function () {
            console.log("取消");
        });
    }

    before_request = 1; // 标识上一次ajax 请求有没回来, 没有回来不再进行下一次
    function verifyForm(form_id,submit_url){
        if(before_request == 0)
            return false;
        $("[id^='err_']").hide();  // 隐藏提示
        $.ajax({
            type : "POST",
            url  : submit_url,
            data : $('#'+form_id).serialize(),// 你的formid
            dataType: 'json',
            error: function(request) {
                layer.msg("服务器繁忙, 请联系管理员!", {icon: 1, time: 2000});
            },
            success: function(data) {
                before_request = 1; // 标识ajax 请求已经返回
                // 验证成功提交表单
                if(data.status == 1)
                {
                    layer.msg(data.msg, {icon: 1, time: 2000},function () {
                    	window.location.href = data.url;
                    });
                }else{
                    layer.msg(data.msg, {icon: 2, time: 2000});
                }
            }
        });
        before_request = 0; // 标识ajax 请求已经发出
    }

    function getOrderAction(){
        var order_id = "{$order.order_id}";
        $.ajax({
            type : "get",
            url  : "{:U('Admin/order/getOrderAction')}",
            data : {order_id:order_id},
            dataType: 'json',
            error: function(request) {
                layer.msg("服务器繁忙, 请联系管理员!", {icon: 1, time: 2000});
            },
            success: function(data) {
                // 验证成功提交表单
                if(data.status == 1)
                {
                    var html = '';
                    for (var i=0; i<data.data.length;i++){
                        html +='<tr><td class="text-center">'+data.data[i].action_user_name+'</td>' +
                                '<td class="text-center">'+data.data[i].log_time+'</td>' +
                                '<td class="text-center">'+data.data[i].order_status+'</td>' +
                                '<td class="text-center">'+data.data[i].pay_status+'</td>' +
                                '<td class="text-center">'+data.data[i].shipping_status+'</td>' +
                                '<td class="text-center">'+data.data[i].status_desc+'</td>' +
                                '<td class="text-center">'+data.data[i].action_note+'</td></tr>'
                    }
                    $('#order_action').html(html);
                }else{
                    layer.msg(data.msg, {icon: 2, time: 2000});
                }
            }
        });
    }

    function deliverGoods(order_id){
        var ordreStr = '',shopStr = '';
        $.ajax({
            type:"POST",
            url:"/index.php?m=Admin&c=ShopOrder&a=getOrderGoodsInfo",
            data:{order_id:order_id},
            dataType:"json",
            success: function (data) {
                $("#old-shop-order-id").val(data.shop_order.shop_order_id);
                ordreStr += '<li style="width: 21%;">' + data.order_sn + '</li><li style="width: 24%;">' + time_format(data.add_time) + '</li><li style="width: 15%;">' + data.user_id + '</li><li style="width: 15%;">' + data.total_amount + '</li><li style="width: 12%;">' + data.shipping_status_desc + '</li><li style="width: 12%;">' + data.delivery_method + '</li>';
                $("#shop-order-info").html(ordreStr);

                shopStr += '<div class="information-list">提货人：<em>' + data.consignee + '</em></div><div class="information-list">自提点：<em>' + data.shop.shop_name + '</em></div><div class="information-list">联系电话：<em>' + data.mobile + '</em></div><div class="information-list">自提时间：<em>' + data.shop_order.take_time + '</em></div>';
                $("#shop-info").html(shopStr);

                $(".z-ztfh-bg,.z-ztfh-pop").show();
            }
        })
    }
    $("#fahuo").click(function(){
        var shopOrderId = $("#shop-order-id").val();
        var oldShopOrderId = $("#old-shop-order-id").val();
        var isCode = $(".ztfh-lab-bg").data().val;
        var newShopOrderId = oldShopOrderId;
        if (isCode == 1) {
            if(shopOrderId != oldShopOrderId){
                layer.alert("提货码错误", {icon: 2});
                return;
            }
            if(shopOrderId == ""){
                layer.alert("请输入提货码", {icon: 2});
                return;
            }
            newShopOrderId = shopOrderId;
        }
        $.ajax({
            type: "POST",
            url: "/index.php?m=Admin&c=ShopOrder&a=writeOff",
            data: {shop_order_id: newShopOrderId},
            dataType: "json",
            success: function (data) {
                if(data.status == 1){
                    location.reload();
                }else{
                    layer.alert(data.msg, {icon: 2});
                }
            }
        })
    })
    $(".ztfh-label label").click(function  () {
        var index= $(this).attr("ints")
        $(".ztfh-label label").removeClass("ztfh-lab-bg");
        $(this).addClass("ztfh-lab-bg");
        if (index==1) {
            $(".z-ztfh-input").show();
        } else{
            $(".z-ztfh-input").hide();
        }
    });
    $(".z-ztfh-close").click(function  () {
        $(".z-ztfh-bg,.z-ztfh-pop").hide();
    })

</script>
</body>
</html>